<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>有效括号</title>

    <script>

        var map = {
            ')': '(',
            ']': '[',
            '}': '{',
        }

        var isValid = function(s) {

            const stack = []

            for(const i in s){
                const c = s[i];

                if(c == '(' || c == '[' || c == '{'){
                    stack.push(c);
                }else{


                    if(stack.pop() == map[c]){
                        continue
                    }else{
                        return false;
                    }

                }
            }

            return stack.length == 0

        };

        console.log(isValid('([]{[()]})'));
        
        

    </script>
</head>

<body>

</body>

</html>